'use strict';

import HTTPUtil from './HTTPUtil'
import Global from './GlobalConst';
import Toast from '../Utils/toast';
export default class DestinationAPIService {
    /**
     * 目的地列表
     */
    static destination(longitude, latitude, page) {
        var url = Global.HOST + '/Rural/destination';
        return new Promise(function (resolve, reject) {
            let formData = new FormData();
            formData.append("longitude", longitude);
            formData.append("latitude", latitude);
            formData.append("page", page);
            console.log('libraryPage',formData);
            HTTPUtil.post(url, formData).then((json) => {
                console.log(url, json);
                if (json.code == true) {
                    resolve(json.result);
                } else {
                    if (json.code == 100) {
                        Toast.show('暂无数据');
                    } else {
                        Toast.show('网络错误');
                    }
                    reject(new Error(json.result));
                }
            }).catch((err)=> {
                reject(new Error(Global.SERVERERR));
            });
        });
    }

    /**
     * 搜索目的地地图列表
     */
    static searchDestinationMap(city, search, longitude, latitude, scope, page) {
        var url = Global.HOST + '/Rural/searchDestinationMap';
        return new Promise(function (resolve, reject) {
            let formData = new FormData();
            formData.append("city", city);
            formData.append("search", search);
            formData.append("longitude", longitude);
            formData.append("latitude", latitude);
            formData.append("scope", scope);
            formData.append("page", page);
            HTTPUtil.post(url, formData).then((json) => {
                console.log(url, json);
                if (json.code == true) {
                    resolve(json.result);
                } else {
                    if (json.code == 100) {
                        Toast.show('暂无数据');
                    } else {
                        Toast.show('网络错误');
                    }
                    reject(new Error(json.result));
                }
            }).catch((err)=> {
                reject(new Error(Global.SERVERERR));
            });
        });
    }

    /**
     * 搜索目的地列表数据
     */
    static searchDestinationlist(city, search,longitude,latitude,scope, page) {
        var url = Global.HOST + '/Rural/searchDestinationlist';
        return new Promise(function (resolve, reject) {
            let formData = new FormData();
            formData.append("city", city);
            formData.append("search", search);
            formData.append("longitude", longitude);
            formData.append("latitude", latitude);
            formData.append("scope", scope);
            formData.append("page", page);
            HTTPUtil.post(url, formData).then((json) => {
                console.log(url, json);
                if (json.code == true) {
                    resolve(json.result);
                } else {
                    if (json.code == 100) {
                        Toast.show('暂无数据');
                    } else {
                        Toast.show('网络错误');
                    }
                    reject(new Error(json.result));
                }
            }).catch((err)=> {
                reject(new Error(Global.SERVERERR));
            });
        });
    }

}
